﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.MefExtensions;
using Microsoft.Practices.Prism.Modularity;

using SearchScreen.SearchScreenModule;


namespace SearchScreen
{
    class Bootstrapper : MefBootstrapper
    {

        protected override DependencyObject CreateShell()
        {
            return new Shell();
            //return this.Container.GetExportedValue<Shell>();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();
            App.Current.MainWindow = (Shell) this.Shell;
            App.Current.MainWindow.Show();

            
            IRegionManager regionManager =
            this.Container.GetExportedValue<IRegionManager>();
            regionManager.RegisterViewWithRegion("Shell", typeof(Shell));
            
        }
        
        
        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new ConfigurationModuleCatalog();
        }
         

        protected override void ConfigureAggregateCatalog()
        {
            base.ConfigureAggregateCatalog();
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
            

            // CriteriaModule is directly referenced in code
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(SearchModule).Assembly));

            // Load the Modules.dll located in the Directory "DirectoryModules"
            DirectoryCatalog catalog = new DirectoryCatalog("DirectoryModules");
            this.AggregateCatalog.Catalogs.Add(catalog);
        }


    }
}
